<?php

namespace app\admin\controller\yeemanage;

use app\common\controller\Backend;
use Yeepay\Yop\Sdk\V1\YopConfig;
use Yeepay\Yop\Sdk\V1\YopRequest;
use Yeepay\Yop\Sdk\V1\YopRsaClient;
use sandpay\HmPayClient;
/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Yeepos extends Backend
{

    /**
     * Yeepos模型对象
     * @var \app\admin\model\yeemanage\Yeepos
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\yeemanage\Yeepos;
        $this->view->assign("isBindList", $this->model->getIsBindList());
        $this->view->assign("statusList", $this->model->getStatusList());
    }



    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */

  /**
     * 商户资料提交
     */
    public function submitdata($ids)
    {
    	$row = $this->model->get($ids);
    	
    	 /*商户私钥*/
        $private_key ="MIIEugIBADANBgkqhkiG9w0BAQEFAASCBKQwggSgAgEAAoIBAQCQMqL/T97RhAophQNRzBwE+vU+59PzfkEzyLZwMaQTduHvdTl4fg6KZ6ATFUgECI2JLpZq3cyjVYSlM9H20bRpZSaoYmsYyNibpf2lg+bMg9G+bS6elHvFn0ZJ+aU40wyWqPjtdLB9JYLDbLVsb6SzHegWovWeWD7vUqCbPhDK24V///baX2zV4609kfa1iBGbynF/0nggHw3leeUW9F8E8twSEF15ObE8ShywOMvi578kv9PUNmSiq8gfc/t8dWVOzi4mbDje49MhxMbuopGv1kcvHBrThTeqQ2plhQSs63AbwLpe4WsZbcNvG9zpjuci8bK1+Zb/3DnkmT4zEu6FAgMBAAECggEAHsQfEPhaoztX67nslmRFSi69atmN2HMEuGbHvjJpPpnr5OqPA41pztADUG8G+Y1VnYJqJ40BX4wcjB79Wnst0hr53414KkaYKMWG0+zLrrElbErhWoZ1zhmI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b/4ngQhjYuED4pI=";

        $request = new YopRequest("app_10088909942", $private_key);
        $Yee = \app\admin\model\yeemanage\Yee::where('store_no',$row->store_no)->find();
        
      
        
        $YeeArea = \app\admin\model\yeemanage\YeeArea::where('provice_code',$Yee['province'])->where('city_code',$Yee['city'])->where('district_code',$Yee['district'])->find();
  
        $shopStro []=array(
             'linkman'=>$Yee['contactName'],
		     'name'=>$Yee['wchatName'],
		     'province'=>$YeeArea['provice'],
		     'city'=>$YeeArea['city'],
		     'county'=>$YeeArea['district'],
		     'address'=>$Yee['address'],
        );
  
        $shopStro = json_encode($shopStro);
        
        $posStr []=array(
             'preShopName'=>$Yee['wchatName'],
		     'serialNumber'=>$row->serialNumber,
		     'isTms'=>true,
		     'mode'=>'QUERY',
        );
          
        $posStr = json_encode($posStr);

        //加入请求参数

        $request->addParam("customer_number",$Yee['merchantNo']);
        $request->addParam("shopStr",$shopStro);
        $request->addParam("posStr",$posStr);
//      //提交Post请求
        $response = YopRsaClient::post("/rest/v1.0/pos/install-pos-with-product", $request);
        $response = json_decode($response);
        $result = $response->result;
        $result = json_decode($result);
        if(isset($result->resultCode) && $result->resultCode == '9')
		{
			$params['shopCustomerNumber']=$result->posInfos[0]->shopCustomerNumber;
			$params['terminal_sn']=$result->posInfos[0]->posCATI;
			$params['is_bind']=1;
            $row->save($params);
			$this->success($result->resultMsg,'','SUCCESS');
		}
        
        $this->success('提交成功',$response);
    }
}
